//
//  UINavigationItem+UI.m
//  XiaoMiao
//
//  Created by 23 on 2018/3/21.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "UINavigationItem+UI.h"

@implementation UINavigationItem (UI)

+(void)load{
    //只需要运行一次
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
        //交换viewWillAppear: 和 glt_viewWillAppear: 方法
        SEL oriSelector = @selector(setRightBarButtonItem:);
        SEL swiSelctor = @selector(app_setRightBarButtonItem:);
        
        //注意：导入头文件 #import <objc/message.h>
        Method oriMethod = class_getInstanceMethod(class, oriSelector);
        Method swiMethod = class_getInstanceMethod(class, swiSelctor);
        
        BOOL success = class_addMethod(class, oriSelector, method_getImplementation(swiMethod), method_getTypeEncoding(swiMethod));
        
        if (success) {
            class_replaceMethod(class, swiSelctor, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
        }else{
            method_exchangeImplementations(oriMethod, swiMethod);
        }
    });
}

#pragma mark - 替换后的子类viewWillAppear
-(void)app_setRightBarButtonItem:(UIBarButtonItem *)item{
    
    [self app_setRightBarButtonItem:item];
    
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0]} forState:UIControlStateNormal];
    
}

@end
